package io.gitee.chearnee.fw.sidecar.workshop;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.concurrent.LinkedBlockingDeque;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 12/19/2022 2:35 PM
 */

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class WorkShop {
    private static final int DEFAULT_QUEUE_SIZE = 100;
    private static final LinkedBlockingDeque<Object> TASK_QUEUE = new LinkedBlockingDeque<>(DEFAULT_QUEUE_SIZE);

    /**
     * 阻塞去获取元素
     *
     * @return
     * @throws InterruptedException
     */
    public static Object take() {
        return TASK_QUEUE.poll();
    }

    /**
     * 添加元素
     *
     * @param task
     */
    public static void add(Object task) {
        TASK_QUEUE.add(task);
        ActionConsumer.trigger();
    }
}
